﻿using System;

namespace _69_泛型方法_泛型
{
    class Program
    {
        static void Main(string[] args)
        {
            Sample s = new Sample();
            s.DoSomething('z');

            s.DoSomething((byte)5);
            s.DoSomething(6.333d);
            s.DoSomething(777);

            //在GetSomeThin方法中由于类型参数作为返回值的类型，无法自动推断类型，所以必须明确指定T的类型
            A xa = s.GetSomething<A>();
            B xb = s.GetSomething<B>();
            Console.Read();

            Console.WriteLine("Hello World!");
        }
    }


    class Sample
    {
        public void DoSomething<T>(T p) where T:struct
        {
            Console.WriteLine("{0}-{1}", p.GetType().Name, p);
        }

        public T GetSomething<T>() where T : class, new()
        {
            return new T();
        }

    }

    public class A { }
    public class B { }
}
